<%@ taglib prefix="page" uri="http://com.qipay/pagelib" %>
<%@ page language="java" import="com.qipay.admin.utils.SiteHelper" contentType="text/html;charset=utf-8" %>
<%@ page import="com.qipay.user.entity.UserLevel" %>
<%@ page import="com.qipay.baas.model.User" %>
<!doctype html>
<html>
<head>
    <script src="<%= request.getAttribute("StaticHost") %>/js/jquery.js"></script>
    <jsp:include page="head.jsp"></jsp:include>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <jsp:include page="nav.jsp"></jsp:include>
    <jsp:include page="left.jsp"></jsp:include>
    <div class="content-wrapper">
        <%
            UserLevel userLevel = (UserLevel) request.getAttribute("level");
            User user1 = (User) request.getAttribute("user");
            String userAuthCode = "";
            if(user1!=null&&user1.getAuthCode()!=null)userAuthCode = user1.getAuthCode();
            String msg = (String) request.getAttribute("msg");
            if(msg!=null){%>
            <script>alert("<%=msg%>");</script>
        <%}
        %>

        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box box-info">
                        <div class="box-header with-border">
                            <h3 class="box-title">编辑管理员</h3>
                        </div>
                        <!-- form start -->
                        <div class="box-body " id="dvContent">
                            <form class="form-horizontal" action="/auth/saveUser" method="POST" id="doc-vld-msg">
                                <div class="form-group">
                                    <label for="txtname" class="col-sm-1 control-label ">管理员名称：</label>
                                    <div class="col-sm-11">
                                        <input type="text" class="form-control" id="txtname" name="name" mush="1"
                                               value="<%=user1==null?"":user1.getName()%>" placeholder="请输入管理员名称">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="txtmchid" class="col-sm-1 control-label">登陆密码：</label>
                                    <div class="col-sm-11">
                                        <input type="password" class="form-control" id="txtmchid" name="password"
                                               value="<%=user1==null?"e10adc3949ba59abbe56e057f20f883e":user1.getPwd()%>" readonly="readonly" >
                                    </div>
                                </div>
                                <!--权限码-->
                                <input id="quanxian11" type="hidden" name="authCode" value="<%=userAuthCode%>"/>
                                <input type="hidden" name="id" value="<%=user1==null?"":user1.getId()%>"/>
                            </form>
                            <div class="box-header with-border" style="margin-top: 50px; ">
                                <h3 class="box-title">权限设定</h3>
                            </div>
                            <div class="form-group">
                                <div >
                                    <div class="checkbox" style="margin-left: 1%;">
                                        <label class="checkbox-inline">
                                            <input type="checkbox" id="inlineCheckbox1" style="zoom:150%;">
                                            <input type="button" id="selectall" class="btn btn-default" value="全选" />
                                        </label>
                                    </div>
                                    <table id="qianxianaqianxian" style="width:400px;" class="table table-hover">

                                    </table>
                                </div>
                            </div>

                        </div>

                        <SCRIPT type="text/javascript">
                            $('#selectall').click(function(){
                                $("input:checkbox").each(function () {
                                    $(this).prop('checked', true);//
                                });
                            });
                            $('#inlineCheckbox1').click(function(){
                                var choose = $(this).prop("checked");
                                if(choose){
                                    $("#selectall").click();
                                }else{
                                    $("input:checkbox").prop("checked",false);
                                }
                            });
                            var selectallflag = true;
                            $(function(){
                                var $maintt=$("#ulLeftMenu").clone();
                                var $maintt1=$maintt.find('.treeview');//导航栏的元素
                                for(var i=0;i<$maintt1.length;i++){
                                    var namename=$maintt1.eq(i).find("a").eq(0).find("span").eq(0).html();
                                    $("#qianxianaqianxian").append('<tr style="background-color:#dcdcdc;">'+
                                        ' <td>'
                                        +' </td>'
                                        +'	<td>'+
                                        '<span style="font-size:20px;">'+namename+'菜单</span>'
                                        +'</td>'+
                                        '</tr>');
                                    for(var j=0;j<$maintt1.eq(i).find("ul").children().length;j++){
                                        var $one=$maintt1.eq(i).find("ul").children().eq(j);//li
                                        var strArray = $one.find("a").html().split(">");
                                        var name=strArray[strArray.length-1];
                                        var value=i+","+j;
                                        var flag="";
                                        if(biduiquanxian(value)){
                                            flag='checked="checked"';
                                        }
                                        $("#qianxianaqianxian").append('<tr>'+
                                            ' <td>'+
                                            ' <input style="zoom:130%;" type="checkbox" class="choose" onchange="makequanxian();" '+flag+' value="'+value+'" />'
                                            +' </td>'
                                            +'<td>'+
                                            name
                                            +'</td>'+
                                            '</tr>');
                                    }
                                }

                                if(selectallflag)$('#selectall').click();
                            });
                            //比对权限，加载页面的时候看看有没有选中
                            function biduiquanxian(a){
                                var qx=$("#quanxian11").val();
                                var ls_flag = false;
                                if(qx!=""){
                                    var qxa=qx.split("-");
                                    for(var i=1;i<qxa.length-1;i++){
                                        if(a==qxa[i]){
                                            return true;
                                            ls_flag = true;
                                        }
                                    }
                                    selectallflag = ls_flag;
                                }else{
                                    selectallflag = false;
                                }
                            }
                            //选择或者取消权限（每次都是重新查看所有的，重新循环写出权限字符串）
                            function makequanxian(){
                                var $cccc=$(".choose");
                                var qianxian="-";
                                for(var i=0;i<$cccc.length;i++){
                                    var $one=$cccc.eq(i);
                                    if($one.is(":checked")){
                                        qianxian=qianxian+$one.val()+"-";
                                    }
                                }
                                $("#quanxian11").val(qianxian);
                                console.log(qianxian);
                            }

                            //提交
                            function madandantijiao(){
                                makequanxian();
                                $('#doc-vld-msg').submit();
                            }

                            function checkedname(){
                                var name=$("#hehename").val();
                                $.ajax({
                                    type: 'POST',
                                    url: "/admin/admin/admin!checkname.action",
                                    data: {"admin.name":name },
                                    sync:true,
                                    dataType: "json",
                                    success: function(data){
                                        if("NO"==data){
                                            alert('"'+name+'"用户名已被占用!');
                                            $("#hehename").val("");
                                        }
                                    },
                                    error:function(){
                                    }
                                });
                            }
                        </SCRIPT>
                        <!-- /.box-body -->
                        <div class="box-footer">
                            <button type="button" class="btn btn-default" onclick="window.history.back()">返回
                            </button>
                            <button onclick = "madandantijiao();"
                                    <%=userLevel.getCode()==1000?"":"disabled = \"disabled\""%> type="button" class="button back-gray" id="btnSearch">确 定</button>
                        </div>
                        <!-- /.box-footer -->
                    </div>
                    <!-- /.box -->
                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <jsp:include page="foot.jsp"></jsp:include>
</div>
<script src="<%= request.getAttribute("StaticHost") %>/js/fastclick.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/adminlte.min.js"></script>
<script>

</script>
</body>
</html>

